﻿Imports System.Text

Namespace StatementSources
    Public Class CreateExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(ByVal name As String, ByVal description As String, ByVal groupId As Integer, ByVal createdBy As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("INSERT [dbo].[ExaminationTypes] ")
            stringBuilder.Append("([Name],[Description],[GroupId],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm]) ")
            stringBuilder.Append("VALUES (@Name,@Description,@GroupId,@CreatedBy,GETDATE(),@CreatedBy,GETDATE());")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@Name", name)
            Parameters.AddWithValue("@Description", description)
            Parameters.AddWithValue("@GroupId", groupId)
            Parameters.AddWithValue("@CreatedBy", createdBy)
        End Sub

    End Class

    Public Class ReadAllExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New()
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[GroupId],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes];")

            Sql = stringBuilder.ToString()
        End Sub

        Public Sub New(ByVal groupId As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[GroupId],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes] ")

            If groupId = -1 Then
                stringBuilder.Append("WHERE [GroupId] BETWEEN 1 AND 4;")
            Else
                stringBuilder.Append("WHERE [GroupId]=@GroupId;")
                Parameters.AddWithValue("@GroupId", groupId)
            End If

            Sql = stringBuilder.ToString()
        End Sub

    End Class

    Public Class ReadByExaminationTypeIdStatementSource
        Inherits BaseStatementSource

        Public Sub New(examinationTypeId As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("SELECT [ExaminationTypeId],[Name],[Description],[GroupId],[CreatedBy],[CreatedDttm],[ModifiedBy],[ModifiedDttm] ")
            stringBuilder.Append("FROM [dbo].[ExaminationTypes] ")
            stringBuilder.Append("WHERE [ExaminationTypeId]=@ExaminationTypeId;")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
        End Sub

    End Class

    Public Class UpdateExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(ByVal examinationTypeId As Integer, ByVal name As String, ByVal description As String, ByVal groupId As Integer, ByVal modifiedBy As Integer)
            Dim stringBuilder As New StringBuilder()
            stringBuilder.Append("UPDATE [dbo].[ExaminationTypes] SET ")
            stringBuilder.Append("[Name]=ISNULL(@Name,[Name]),")
            stringBuilder.Append("[Description]=ISNULL(@Description,[Description]),")
            stringBuilder.Append("[GroupId]=ISNULL(@GroupId,[GroupId]),")
            stringBuilder.Append("[ModifiedBy]=@ModifiedBy,")
            stringBuilder.Append("[ModifiedDttm]=GETDATE() ")
            stringBuilder.Append("WHERE [ExaminationTypeId]=@ExaminationTypeId;")

            Sql = stringBuilder.ToString()

            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
            Parameters.AddWithValue("@Name", name)
            Parameters.AddWithValue("@Description", description)
            Parameters.AddWithValue("@GroupId", groupId)
            Parameters.AddWithValue("@ModifiedBy", modifiedBy)
        End Sub

    End Class

    Public Class DeleteExaminationTypeStatementSource
        Inherits BaseStatementSource

        Public Sub New(examinationTypeId As Integer)
            Sql = "DELETE FROM [dbo].[ExaminationTypes] WHERE [ExaminationTypeId]=@ExaminationTypeId;"
            Parameters.AddWithValue("@ExaminationTypeId", examinationTypeId)
        End Sub

    End Class
End Namespace
